package com.bosicloud.cmb.ibp.api.manager.api;

import com.bosicloud.cmb.ibp.api.manager.commom.constant.UrlDefine;
import com.bosicloud.cmb.ibp.api.manager.commom.model.*;
import com.bosicloud.cmb.ibp.api.manager.commom.vo.*;
import com.bosicloud.cmb.ibp.commom.dto.Pagination;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@FeignClient(value = "ApiManagerService", url = "${ibp.service.api-manager-url}")
public interface ApiManagerClient {


    @GetMapping(UrlDefine.ALL_CATEGORY)
    List<IbpApiCategory> getAllCategory();

    @GetMapping(UrlDefine.API_PAGE + "/{currentPage}/{pageSize}")
    Object pagingApi(@PathVariable(value = "currentPage") Integer currentPage,
                     @PathVariable(value = "pageSize") Integer pageSize,
                     @RequestParam(required = false, value = "categoryId") Integer categoryId);


    @GetMapping(UrlDefine.SEARCH_API + "/{currentPage}/{pageSize}")
    Pagination<IbpApiVO> searchApi(@PathVariable(value = "currentPage") Integer currentPage,
                                   @PathVariable(value = "pageSize") Integer pageSize,
                                   @RequestParam(required = false, value = "categoryId") Integer categoryId,
                                   @RequestParam(required = false, value = "searchText") String searchText);


    @GetMapping(UrlDefine.API_DETAIL + "/{apiId}")
    IbpApiVO searchApiDetail(@PathVariable(value = "apiId") Integer apiId);


    @GetMapping(UrlDefine.METHOD_LIST + "/{apiId}")
    List<ApiMethodListVO> searchApiMethodListByApiId(@PathVariable(value = "apiId") Integer apiId);


    @GetMapping(UrlDefine.METHOD_INFO + "/{docsId}")
    MethodInfoVO searchApiMethodInfoByDocsId(@PathVariable(value = "docsId") Integer docsId);

    @PostMapping(UrlDefine.ADD_API)
    String addApi(@RequestBody IbpApi ibpApi);

    @PutMapping(UrlDefine.METHOD_INFO)
    String updateApiMethodInfo(@RequestBody MethodInfoVO methodInfoVO);


    @PostMapping(value = UrlDefine.DEPLOY_API)
    String deployApi(@RequestBody DeployApiParamVO deployApiParamVO);

    @GetMapping(UrlDefine.API_LIST + "/{currentPage}/{pageSize}/users/{userId}")
    Pagination<IbpApiVO> searchApiDeveloperList(@PathVariable(value = "currentPage") Integer currentPage,
                                                @PathVariable(value = "pageSize") Integer pageSize,
                                                @PathVariable(value = "userId") Integer userId);

    @PostMapping(value = UrlDefine.SUBSCRIBE_API)
    String subscribeApi(@RequestBody SubscribeApiParamVO subscribeApiParamVO);


    @PostMapping(value = UrlDefine.UNSUBSCRIBE_API)
    String unSubscribeApi(@RequestBody SubscribeApiParamVO subscribeApiParamVO);


    @DeleteMapping(value = UrlDefine.DELETE_API)
    String deleteApi(@RequestBody DeleteApiParamVO deleteApiParamVO);


    @GetMapping(value = UrlDefine.SUBSCRIBE_API_LIST + "/{currentPage}/{pageSize}/users/{userId}",
            produces = MediaType.APPLICATION_JSON_VALUE)
    Pagination<SubscribeApiListVO> subscribeApiList(@PathVariable(value = "currentPage") Integer currentPage,
                                                    @PathVariable(value = "pageSize") Integer pageSize,
                                                    @PathVariable(value = "userId") Integer userId);


    @GetMapping(value = UrlDefine.CHECK_SUBSCRIBE_AVAILABLE + "/{apiId}/users/{userId}", produces = MediaType.APPLICATION_JSON_VALUE)
    Boolean checkSubscribeIsAvailable(@PathVariable(value = "apiId") Integer apiId,
                                      @PathVariable(value = "userId") Integer userId);


    @GetMapping(value = UrlDefine.DEPLOY_FAIL_MSG + "/{apiId}/{env}", produces = MediaType.APPLICATION_JSON_VALUE)
    IbpApiAwsFailtMsg searchFailMsg(@PathVariable(value = "apiId") Integer apiId,
                                    @PathVariable(value = "env") String env);


    @GetMapping(value = UrlDefine.DEPLOY_FAIL_MSG + "/{apiId}/{bizType}", produces = MediaType.APPLICATION_JSON_VALUE)
    IbpApiAwsFailtMsg searchFailMsg(@PathVariable(value = "apiId") Integer apiId,
                                    @PathVariable(value = "bizType") String bizType,
                                    @RequestParam(value = "context", required = false) String context);


    @PutMapping(value = UrlDefine.PUBLIC_API + "/{apiId}", produces = MediaType.APPLICATION_JSON_VALUE)
    String isPublicAPi(@PathVariable(value = "apiId") Integer apiId);


    @GetMapping(value = UrlDefine.USAGE_PLAN_LIST + "/{apiId}", produces = MediaType.APPLICATION_JSON_VALUE)
    List<IbpApiUsagePlan> searchUsagePlanList(@PathVariable(value = "apiId") Integer apiId);


    @GetMapping(value = UrlDefine.CHECK_API_NAME + "/{apiName}", produces = MediaType.APPLICATION_JSON_VALUE)
    Boolean checkApiName(@PathVariable(value = "apiName") String apiName);

    @GetMapping(value = UrlDefine.SEARCH_SUBSCRIBE_INFO + "/{userId}/{apiId}", produces = MediaType.APPLICATION_JSON_VALUE)
    IbpUserConsumerApi searchUserConsumerApi(@PathVariable(value = "apiId") Integer apiId,
                                             @PathVariable(value = "userId") Integer userId);

    @GetMapping(value = UrlDefine.RESPONSE_CODE_LIST + "/{docsId}", produces = MediaType.APPLICATION_JSON_VALUE)
    List<IbpApiDocResponseMgs> searchApiDocResponseMgsByDocsId(@PathVariable(value = "docsId") Integer docsId);

    @GetMapping(value = UrlDefine.RESPONSE_MODEL_HEADERS + "/{responseMsgId}", produces = MediaType.APPLICATION_JSON_VALUE)
    Map<String, Object> searchResponseModelAndHeadersById(@PathVariable(value = "responseMsgId") Integer responseMsgId);
}
